<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/8/29
 * Time: 16:28
 */
class wx{
    public $appid="wx8383cd9c0fbf7931";
    public $secret="80af3fab554aebc278fbcd34d868ddf8";
    //token
    public function __construct(){
        $signature =isset($_GET['signature'])?$_GET['signature']:"";
        $timestamp =isset($_GET['timestamp'])?$_GET['timestamp']:"";
        if(!empty($signature) && !empty($timestamp )){
            $this->volid();
        }else{
            echo "ddd";
            echo "ddd";
        }
    }
    //验证
    function valid(){
        $signature=$_GET['signature'];
        $timestamp=$_GET['timestamp'];
        $nonce=$_GET['nonce'];
        $echostr=$_GET['echostr'];
        $tmpArr=array($timestamp,$nonce,'p56');
        sort($tmpArr,SORT_STRING);
        $tmpStr=implode($tmpArr);
        $tmpStr=sha1($tmpStr);
        if($signature==$tmpStr){
            echo $echostr;
            exit;
        }
    }
}

$wx=new wx();